package com.hyh.admin.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyh.ad.common.core.domain.model.SysMenu;
import com.hyh.ad.common.core.domain.model.SysRole;
import com.hyh.admin.sys.mapper.SysRoleMapper;
import com.hyh.admin.sys.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 系统角色信息表(SysRole)表服务实现类
 * @author hyh
 */

@Service
public class SysRoleServiceImpl implements ISysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> selectListSysRolePage(SysRole sysRoles) {
        LambdaQueryWrapper<SysRole> query = new LambdaQueryWrapper<>(sysRoles);
        query.orderByAsc(SysRole::getCreateTime);
        return sysRoleMapper.selectList(query);
    }

    @Override
    public SysRole selectSysRoleById(Long id) {
        return sysRoleMapper.selectById(id);
    }

    @Override
    public int insertSysRole(SysRole sysRole) {
        return sysRoleMapper.insert(sysRole);
    }

    @Override
    public int updateSysRole(SysRole sysRole) {
        return sysRoleMapper.updateById(sysRole);
    }

    @Override
    public int deleteSysRoleByIds(Long[] ids) {
        return sysRoleMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public int assignRoles(Long userId, Long[] roleIds) {
        return sysRoleMapper.assignRoles(userId, roleIds);
    }

    @Override
    public int assignMenus(Long roleId, Long[] menuIds) {
        return sysRoleMapper.assignMenus(roleId, menuIds);
    }

    @Override
    public List<SysMenu> selectRoleMenus(Long roleId) {
        return sysRoleMapper.selectRoleMenus(roleId);
    }

    @Override
    public int updateStatus(SysRole sysRole) {
        return sysRoleMapper.updateById(sysRole);
    }
}
